import React, { Component, PropTypes } from 'react';
import { Form, Icon, Input, Rate, Button, Checkbox, message, Modal } from 'antd';
import Md5 from 'js-md5';
import { connect } from 'dva'
import Style from './index.less';
import Service from '../service';
import Moment from 'moment';
const FormItem = Form.Item;
var map, point;

class App extends Component {
  constructor(props) {
    super(props);
    this.state = {
      data: [],
      rateValue: 0
    }
  }
  componentDidMount() {
    let self = this;
    const token = localStorage.getItem('token');
    let videoData = self.props.videoData;
    // console.log(videoData)
    if (videoData && videoData.id) {
      self.setState({
        videoData: videoData
      })
    } else {
      message.error('快递信息不存在，请从视频列表重新进入!', 1.5, function () {
        self.context.router.push(`/uvideolist`);
      });
      self.messageConfig();
    }

  }
  componentWillUnmount() {
    let self = this;
    self.props.urlStatus({
      url: '/ucomment'
    });
  }

  // 返回
  returnFun = () => {
    history.back(-1);
    // this.context.router.push(`/uindex`);
  }
  //  签收
  signFun = () => {

  }
  // 拒签
  nosignFun = () => {
    this.context.router.push(`/ucomment`);
  }
  // 筛选评分
  rateHandleChange = (value) => {
    // console.log(value)
    this.setState({ rateValue: value });
  }
  /* 控制提示 */
  messageConfig() {
    message.config({
      top: 100, // 消息距离顶部的位置
      duration: 2, // 默认自动关闭延时，单位秒
      maxCount: 1, // 最大显示数, 超过限制时，最早的消息会被自动关闭
    });
  }
  // 评分提交
  rateSubmit = () => {
    let self = this;
    const token = localStorage.getItem('token');
    if (!self.state.rateValue) {
      message.error('请给快递员打分再提交噢！');
      self.messageConfig();
      return false;
    }
    self.props.comment({
      params: {
        token: token,
        id: self.state.videoData.id,
        star: self.state.rateValue
      },
      func: function (result) {
        message.success('评价成功!', 1.5, function () {
          self.context.router.push(`/uvideolist`);
        });
      }
    })
  }
  // 我的
  myUrlFun = () => {
    this.context.router.push(`/umy`);
  }
  render() {
    const { getFieldDecorator } = this.props.form;
    return (
      <div className={Style.wrap}>
        <div className={Style.headWrap}>
          <div className={Style.navTitle}>
            <span className={Style.arrow} onClick={this.returnFun}>
              <Icon type="left" />
            </span>
            进行评价
            <span className={Style.arrow + ' ' + Style.arrowText} onClick={this.myUrlFun}>我的</span>
          </div>
        </div>
        <div className={Style.dataWrap}>
          <div className={Style.commentWrap}>
            <div className={Style.commentItem}>
              <dl>
                <dt><span className={Style.rateIcon}></span>评价此次服务</dt>
                <dd><Rate onChange={this.rateHandleChange} value={this.state.rateValue} /></dd>
              </dl>
            </div>
          </div>
          <div className={Style.btn + ' ' + Style.blueBtn + ' ' + Style.mt10} onClick={this.rateSubmit}>
            提交
          </div>
        </div>
      </div>
    )
  }
}

App.contextTypes = {
  router: React.PropTypes.object
}

function mapStateToProps(state, ownProps) {
  return {
    videoData: state.umodel.videoData
  }
}
function dispatchToProps(dispatch) {
  return {
    comment(payload, params) {
      dispatch({
        type: 'umodel/comment',
        payload
      })
    },
    urlStatus(payload, params) {
      dispatch({
        type: 'myHome/urlStatus',
        payload
      })
    }

  }
}
export default connect(mapStateToProps, dispatchToProps)(Form.create()(App));
